# 导入模块
import cv2 as cv
import time

# 自动录入
def savea(name,num):
    imgPath = './jm/' # 图片路径

    i = 1 # 循环数
    cap = cv.VideoCapture(0) # 打开摄像头
    for i in range(50):
        ret_flag, Vshow = cap.read()    # 得到每帧图像
        cv.imshow("Capture_Test", Vshow)    # 显示图像
        imgname = str(num) + "." + name + ".jpg"    # 图片名
        k = cv.waitKey(1) & 0XFF    # 按键识别
        cv.imwrite(imgPath + imgname, Vshow)
        print("success to save " + imgname)
        num += 1    # 序号加一
        i += 1  # 循环数加一
        time.sleep(0.05)    # 睡眠0.05s
    print("It's ok!")
    cap.release()   # 释放摄像头
    cv.destroyAllWindows()  # 释放内存

def saves(name,num):
    imgPath = './jm/'

    cap = cv.VideoCapture(0)
    while (cap.isOpened()):  # 检测是否在开启状态
        ret_flag, Vshow = cap.read()  # 得到每帧图像
        cv.imshow("Capture_Test", Vshow)  # 显示图像
        imgname = str(num) + "." + name + ".jpg"
        k = cv.waitKey(1) & 0xFF  # 按键判断
        if k == ord('s'):  # 保存
            cv.imwrite(imgPath + imgname, Vshow)    # 保存图片
            print("success to save" + str(num) + ".jpg")
            print("-------------------")
            num += 1    # 序号
        elif k == ord(' '):  # 退出
            break
    print("It's ok!")
    cap.release()   # 释放摄像头
    cv.destroyAllWindows()  # 释放内存